/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */
/******************************************************************************
 * @version: V1.0.0  demo
 ******************************************************************************/

/*!
* @file clock_config.c
*
* @brief This file provides clock config integration functions.
*
*/

/* ===========================================  Includes  =========================================== */
#include "clock_config.h"

/* ============================================  Define  ============================================ */


/* ===========================================  Typedef  ============================================ */


/* ==========================================  Variables  =========================================== */


/* *************************************************************************
 * Configuration structure for peripheral clock configuration 0
 * ************************************************************************* */
/*! @brief peripheral clock configuration 0 */
peripheral_clock_config_t peripheralClockConfig0[NUM_OF_PERIPHERAL_CLOCKS_0] = {
    {
        .clockName        = I2C0_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = TIMER_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = SPI0_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = SPI1_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = SPI2_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = ADC0_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = ADC1_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = CAN0_CLK,
        .clkSrc           = CORE_CLK,
        .divider          = DIVIDE_BY_ONE,
    },
    {
        .clockName        = CAN1_CLK,
        .clkSrc           = CORE_CLK,
        .divider          = DIVIDE_BY_ONE,
    },
    {
        .clockName        = CAN2_CLK,
        .clkSrc           = CORE_CLK,
        .divider          = DIVIDE_BY_ONE,
    },
    {
        .clockName        = CAN3_CLK,
        .clkSrc           = CORE_CLK,
        .divider          = DIVIDE_BY_ONE,
    },
    {
        .clockName        = PCT_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = EIO_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = EIO_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = UART0_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = UART1_CLK,
        .clkSrc           = HSEDIV2_CLK,
    },
    {
        .clockName        = UART2_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = UART3_CLK,
        .clkSrc           = HSIDIV2_CLK,
    },
    {
        .clockName        = PWM0_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
    {
        .clockName        = PWM1_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
    {
        .clockName        = PWM2_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
    {
        .clockName        = PWM3_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
    {
        .clockName        = PWM4_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
    {
        .clockName        = PWM5_CLK,
        .clkSrc           = HSIDIV1_CLK,
    },
};

/* *************************************************************************
 * Configuration structure for Clock Configuration 0
 * ************************************************************************* */
/*! @brief User Configuration structure clockMan1_InitConfig0 */
clock_manager_user_config_t clockMan1_InitConfig0 = {
    .ckgenConfig =
    {
        .hsiConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            /* HSIDIV */
            .div1             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< HSIDIV1    */
            .div2             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< HSIDIV2    */
        },
        .vhsiConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            /* VHSIDIV */
            .div1             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< VHSIDIV1   */
            .div2             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< VHSIDIV2   */
        },
        .rtcConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            .rtcClkInFreq     = 0U,                                            /*!< RTC_CLKIN  */
        },
        .hseConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            .freq             = 8000000U,                                      /*!< Frequency  */
            /* HSEREF */
            .extRef           = CKGEN_HSE_REF_OSC,                             /*!< HSEREF     */
            /* HSEDIV */
            .div1             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< HSEDIV1    */
            .div2             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< HSEDIV2    */
        },
        .spllConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            /* SPLLCFG */
            .prediv           = (uint8_t)CKGEN_SPLL_CLOCK_PREDIV_BY_1,         /*!< PREDIV     */
            .fbkdiv           = (uint8_t)120U,                                  /*!< FBKDIV     */
            .posdiv           = 8U / 2U,                                       /*!< POSDIV     */
            .src              = 1U,                                            /*!< SOURCE     */
            /* SPLLDIV */
            .div1             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< SPLLDIV1   */
            .div2             = CKGEN_ASYNC_CLOCK_DIV_BY_1,                    /*!< SPLLDIV2   */
        },
        .clockOutConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            .source           = CKGEN_CLKOUT_SEL_HSI_CLK,                      /*!< CLKOUTSEL  */
        },
        .clockModeConfig =
        {
            .initialize       = true,                                          /*!< Initialize */
            .rccrConfig =                              /*!< RCCR - Run Clock Control Register  */
            {
                .src          = CKGEN_SYSTEM_CLOCK_SRC_SPLL,                   /*!< SCS        */
                .divCore      = CKGEN_SYSTEM_CLOCK_DIV_BY_1,                   /*!< DIVCORE    */
                .divBus       = CKGEN_SYSTEM_CLOCK_DIV_BY_2,                   /*!< DIVBUS     */
            },
            .vccrConfig =                              /*!< VCCR - VLPR Clock Control Register */
            {
                .src          = CKGEN_SYSTEM_CLOCK_SRC_HSI,                    /*!< SCS        */
                .divCore      = CKGEN_SYSTEM_CLOCK_DIV_BY_1,                   /*!< DIVCORE    */
                .divBus       = CKGEN_SYSTEM_CLOCK_DIV_BY_2,                   /*!< DIVBUS     */
            },
        },
    },
    .pccConfig =
    {
        .peripheralClocks = peripheralClockConfig0,                            /*!< Peripheral clock control configurations  */
        .count = NUM_OF_PERIPHERAL_CLOCKS_0,                                   /*!< Number of the peripheral clock control configurations  */
    },
    .simConfig =
    {
        .clockOutConfig =                              /*!< Clock Out Configuration.           */
        {
            .initialize       = true,                                          /*!< Initialize */
            .enable           = false, 
            .source           = CKGEN_CLKOUT_SEL_HSI_CLK,                      /*!< CLKOUTSEL  */
            .divider          = CKGEN_CLKOUT_DIV_BY_2,                         /*!< CLKOUTDIV  */
        },
        .lpClockConfig =                               /*!< Low Power Clock Configuration.     */
        {
            .initialize       = true,                                          /*!< Initialize */
            .sourceLsiClk     = LSI_CLK_SEL_128K,                              /*!< LSICLKSEL  */
            .sourceRtcClk     = RTC_CLK_SEL_LSI_32K,                          /*!< RTCCLKSEL  */
        },
        .tclkConfig =                                  /*!< Tclk Clock Configuration.          */
        {
            .initialize       = true,                                          /*!< Initialize */
            .tclkFreq[0U]     = 0UL,                                           /*!< TCLK0      */
            .tclkFreq[1U]     = 0UL,                                           /*!< TCLK1      */
            .tclkFreq[2U]     = 0UL,                                           /*!< TCLK2      */
        },
        .traceClockConfig =                            /*!< Debug Trace Clock Configuration.   */
        {
            .initialize       = true,                                          /*!< Initialize */
            .divider          = 0U,                                            /*!< TRACEDIV   */
        },
    },
};

/*! @brief Array of pointers to User configuration structures */
clock_manager_user_config_t const * g_clockManConfigsArr[] = {
    &clockMan1_InitConfig0
};
/*! @brief Array of pointers to User defined Callbacks configuration structures */
clock_manager_callback_user_config_t * g_clockManCallbacksArr[] = {(void*)0};

/* ====================================  Functions declaration  ===================================== */


/* ======================================  Functions define  ======================================== */

/* =============================================  EOF  ============================================== */
